package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhentao.model.dto.product.BrandDto;
import com.zhentao.model.entity.product.Brand;
import com.zhentao.model.vo.common.Result;
import com.zhentao.model.vo.common.ResultCodeEnum;
import com.zhentao.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author : mgh
 * @date : 2024-08-19 16:07
 * @effect : 当前类的作用是
 * @projectTeam :
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @PostMapping("/BrandFindAll")
    public Result BrandFindAll(){
        LambdaQueryWrapper<Brand> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(true,Brand::getIsDeleted,0);
        List<Brand> list = brandService.list(wrapper);
        return Result.build(list , ResultCodeEnum.SUCCESS) ;
    }
    //    展示
    @PostMapping("list")
//    @CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
    public Result list(@RequestBody BrandDto brandDto){
        Result brandlist = brandService.brandlist(brandDto);
        return brandlist;
    }
    //    前端添加图片的路径添加到minio
    @PostMapping("file")
    public Result file(MultipartFile file){
        Result file1 = brandService.file(file);
        return file1;
    }

    //    添加
    @PostMapping("save")
    public Result save(@RequestBody Brand brand){
        return Result.build(brandService.brandsave(brand),ResultCodeEnum.SUCCESS);
    }
    //    修改
    @PostMapping("update")
    public Result update(@RequestBody Brand brand){
        return Result.build(brandService.brandupdadte(brand),ResultCodeEnum.SUCCESS);
    }

    //    删除
    @PostMapping("delete")
    public Result delete(@RequestParam Long id){
        Result branddlete = brandService.branddlete(id);
        return branddlete;
    }




}
